/*
 * Created by JFormDesigner on Wed Jul 03 23:49:14 CST 2024
 */

package scct.ZhuZhouXing.ui;

import jdk.nashorn.internal.scripts.JO;
import scct.ZhuZhouXing.dao.StaffDao;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

/**
 * @author zr155
 */
public class DlgStaffAdd extends JDialog {
    public DlgStaffAdd(Window owner) {
        super(owner);
        initComponents();
    }

    private void btnAdd(ActionEvent e) {
        String name = txtname.getText();
        int age = Integer.parseInt(txtprice.getModel().getValue().toString());
        String YG = txtyg.getSelectedItem().toString();
        String XZ = comleibie.getSelectedItem().toString();
        String sex = radioButton1.isSelected() ? "男" : "女";
        String dh = textField2.getText();
        StaffDao staffDao =new StaffDao();
        if (staffDao.addStaff(name,sex,age,YG,dh,XZ)){
            JOptionPane.showMessageDialog(this,"添加成功！");
            PaneStaffManager.getTable();
            this.dispose();
        }else {
            JOptionPane.showMessageDialog(this,"添加失败！");
        }
    }

    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents  @formatter:off
        // Generated using JFormDesigner Evaluation license - zhur
        label1 = new JLabel();
        label2 = new JLabel();
        label5 = new JLabel();
        label6 = new JLabel();
        label7 = new JLabel();
        txtname = new JTextField();
        label8 = new JLabel();
        label9 = new JLabel();
        txtprice = new JSpinner();
        comleibie = new JComboBox<>();
        radioButton1 = new JRadioButton();
        radioButton2 = new JRadioButton();
        textField2 = new JTextField();
        txtyg = new JComboBox<>();
        btnAdd = new JButton();
        button2 = new JButton();

        //======== this ========
        setFont(this.getFont().deriveFont(this.getFont().getSize() + 4f));
        Container contentPane = getContentPane();
        contentPane.setLayout(null);

        //---- label1 ----
        label1.setText("\u6dfb\u52a0\u5458\u5de5");
        label1.setFont(new Font("Microsoft JhengHei UI", label1.getFont().getStyle() | Font.BOLD, label1.getFont().getSize() + 10));
        contentPane.add(label1);
        label1.setBounds(240, 15, 160, 55);

        //---- label2 ----
        label2.setText("\u59d3\u540d");
        label2.setFont(label2.getFont().deriveFont(label2.getFont().getSize() + 6f));
        contentPane.add(label2);
        label2.setBounds(new Rectangle(new Point(170, 70), label2.getPreferredSize()));

        //---- label5 ----
        label5.setText("\u85aa\u8d44");
        label5.setFont(label5.getFont().deriveFont(label5.getFont().getSize() + 6f));
        contentPane.add(label5);
        label5.setBounds(new Rectangle(new Point(170, 220), label5.getPreferredSize()));

        //---- label6 ----
        label6.setText("\u6027\u522b");
        label6.setFont(label6.getFont().deriveFont(label6.getFont().getSize() + 6f));
        contentPane.add(label6);
        label6.setBounds(new Rectangle(new Point(170, 270), label6.getPreferredSize()));

        //---- label7 ----
        label7.setText("\u7535\u8bdd");
        label7.setFont(label7.getFont().deriveFont(label7.getFont().getSize() + 6f));
        contentPane.add(label7);
        label7.setBounds(new Rectangle(new Point(170, 320), label7.getPreferredSize()));
        contentPane.add(txtname);
        txtname.setBounds(250, 70, 165, 30);

        //---- label8 ----
        label8.setText("\u5e74\u9f84");
        label8.setFont(label8.getFont().deriveFont(label8.getFont().getSize() + 6f));
        contentPane.add(label8);
        label8.setBounds(new Rectangle(new Point(170, 120), label8.getPreferredSize()));

        //---- label9 ----
        label9.setText("\u804c\u4f4d");
        label9.setFont(label9.getFont().deriveFont(label9.getFont().getSize() + 6f));
        contentPane.add(label9);
        label9.setBounds(new Rectangle(new Point(170, 170), label9.getPreferredSize()));

        //---- txtprice ----
        txtprice.setModel(new SpinnerNumberModel((byte) 18, (byte) 18, (byte) 60, (byte) 1));
        contentPane.add(txtprice);
        txtprice.setBounds(250, 120, 165, 30);

        //---- comleibie ----
        comleibie.setModel(new DefaultComboBoxModel<>(new String[] {
            "4000",
            "4500",
            "6000",
            "6500",
            "8000",
            "8500"
        }));
        contentPane.add(comleibie);
        comleibie.setBounds(250, 220, 165, 30);

        //---- radioButton1 ----
        radioButton1.setText("\u7537");
        radioButton1.setSelected(true);
        contentPane.add(radioButton1);
        radioButton1.setBounds(new Rectangle(new Point(270, 270), radioButton1.getPreferredSize()));

        //---- radioButton2 ----
        radioButton2.setText("\u5973");
        contentPane.add(radioButton2);
        radioButton2.setBounds(new Rectangle(new Point(340, 270), radioButton2.getPreferredSize()));
        contentPane.add(textField2);
        textField2.setBounds(250, 320, 165, 30);

        //---- txtyg ----
        txtyg.setModel(new DefaultComboBoxModel<>(new String[] {
            "\u5458\u5de5",
            "\u5c0f\u7ec4\u7ec4\u957f",
            "\u4e3b\u7ba1",
            "\u526f\u7ecf\u7406",
            "\u7ecf\u7406",
            "\u526f\u5e97\u957f",
            "\u5e97\u957f"
        }));
        contentPane.add(txtyg);
        txtyg.setBounds(250, 170, 165, 30);

        //---- btnAdd ----
        btnAdd.setText("\u6dfb\u52a0");
        btnAdd.setFont(btnAdd.getFont().deriveFont(btnAdd.getFont().getSize() + 10f));
        btnAdd.addActionListener(e -> btnAdd(e));
        contentPane.add(btnAdd);
        btnAdd.setBounds(new Rectangle(new Point(155, 380), btnAdd.getPreferredSize()));

        //---- button2 ----
        button2.setText("\u53d6\u6d88");
        button2.setFont(button2.getFont().deriveFont(button2.getFont().getSize() + 10f));
        contentPane.add(button2);
        button2.setBounds(new Rectangle(new Point(345, 380), button2.getPreferredSize()));

        {
            // compute preferred size
            Dimension preferredSize = new Dimension();
            for(int i = 0; i < contentPane.getComponentCount(); i++) {
                Rectangle bounds = contentPane.getComponent(i).getBounds();
                preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
            }
            Insets insets = contentPane.getInsets();
            preferredSize.width += insets.right;
            preferredSize.height += insets.bottom;
            contentPane.setMinimumSize(preferredSize);
            contentPane.setPreferredSize(preferredSize);
        }
        setSize(630, 505);
        setLocationRelativeTo(getOwner());

        //---- buttonGroup1 ----
        ButtonGroup buttonGroup1 = new ButtonGroup();
        buttonGroup1.add(radioButton1);
        buttonGroup1.add(radioButton2);
        // JFormDesigner - End of component initialization  //GEN-END:initComponents  @formatter:on
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables  @formatter:off
    // Generated using JFormDesigner Evaluation license - zhur
    private JLabel label1;
    private JLabel label2;
    private JLabel label5;
    private JLabel label6;
    private JLabel label7;
    private JTextField txtname;
    private JLabel label8;
    private JLabel label9;
    private JSpinner txtprice;
    private JComboBox<String> comleibie;
    private JRadioButton radioButton1;
    private JRadioButton radioButton2;
    private JTextField textField2;
    private JComboBox<String> txtyg;
    private JButton btnAdd;
    private JButton button2;
    // JFormDesigner - End of variables declaration  //GEN-END:variables  @formatter:on
}
